# include <bits/stdc++.h>
# define MAXN 10023
using namespace std;

// f[i][j] 表示在第i秒体力剩余j时的最大跑步距离
// f[i][j] = max(f[i - 1][j - 1] + a[i], f[i - 1][j + 1]);
int f[MAXN][510], n, m, a[MAXN];

int main() {
    freopen("cowrun.in", "r", stdin);
    freopen("cowrun.out", "w", stdout);
    cin >> n >> m;
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    for (int i = 1; i <= n; i++) {
        f[i][0] = f[i - 1][0];
        for (int j = 1; j <= m; j++) {
            if(i >= j) f[i][0] = max(f[i][0], f[i - j][j]);
            f[i][j] = max(f[i][j], f[i - 1][j - 1] + a[i]);
        }
    }
    printf("%d\n", f[n][0]);
}